#include "array_functions.h"

/**
 * Calculate the array size for the level
 */
int arraySize(int levelNumber) {
	
	int i, aux;
	
	aux = 1;
	
	for(i = 1; i < levelNumber; i++) {
		aux *= 2;
	}
	
    	return ARRAY_SIZE_INIT*aux;
    
}

/**
 * Create a random array of size 'size', with random integers between 'min' and 'max'
 */
void createRandomArray(int *array, int size, int min, int max) {
	
    int i;
	
    for(i = 0; i < size; i++) {
        array[i] = (rand()%(max-min+1)) + min;
	}
}

/**
 * Compare function used in 'qsort()' function
 */
int compareFunction(const void *a, const void *b) {
	
	int *x = (int *) a;
	int *y = (int *) b;
	
	return *x - *y;
	
}

/**
 * Prints the array
 */
void printArray(int *array, int size) {
	
    int i;
    
	fprintf(stderr, "\n");
    
    for(i = 0; i < size; i++){
		fprintf(stderr, "%d: %3d\n",i+1,array[i]);
    }
    
	fprintf(stderr, "\n");

}

